<?php

namespace app\admin\controller;

class Common extends \think\Controller {

    public function login() {
        $nick = input('nick');
        $password = input('password');
        if (!empty($nick) && !empty($password)) {
            $cookie['id'] = 1;
            $cookie['nick'] = 'admin';
            $cookie['power'] = '0';
            $remember = input('remember');
            if ($remember) {
                $now_time = $_SERVER['REQUEST_TIME'];
                $h = date('H', $now_time);
                $i = date('i', $now_time);
                $s = date('s', $now_time);
                $time = 86400 - $h * 3600 - $i * 60 - $s;
                cookie('admin', $cookie, $time);
            } else {
                cookie('admin', $cookie);
            }
//            $this->redirect('index/index');
            $return['flag']=true;
            $return['msg']='登录成功';
            $return['url']=url('index/index');
            exit(json_encode($return));
        } else {
            return $this->fetch();
        }
    }

    public function logout() {
        cookie('admin', null);
        $return['flag']=true;
        $return['url']=url('common/login');
        exit(json_encode($return));
    }

}
